//
//  Config.h
//  DDProcject_01
//
//  Created by iOS on 16/11/16.
//  Copyright © 2016年 IOS. All rights reserved.
//

#ifndef Config_h
#define Config_h
#pragma mark - DEBUG
#ifdef DEBUG
// 定义是输出Log
#define DLog(format, ...) NSLog(@"Line[%d] %s " format, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__)
#else
// 定义是输出Log
#define DLog(format, ...)
#endif
// 只输出类名
#define LogClassName DLog(@"")



#pragma mark - 屏幕
#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define isPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)


#define kScrrenBounds [[UIScreen mainScreen] bounds]
#define kStatusBarHeight 20
#define kNavigationBarHeight 44
#define kNavigationBarIcon 20
#define kTabBarHeight 50
#define kTabBarIcon 30
#define kNavAndStatusHeight 64


#pragma mark - 系统相关
// 检查系统版本
#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

// 获取版本
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]

//获取当前语言
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])


#pragma mark - 定义弱引用、强引用

#define WeakSelf(weakSelf)  __weak __typeof(&*self)weakSelf = self

#define ESWeak(var, weakVar) __weak __typeof(&*var) weakVar = var
#define ESStrong_DoNotCheckNil(weakVar, _var) __typeof(&*weakVar) _var = weakVar
#define ESStrong(weakVar, _var) ESStrong_DoNotCheckNil(weakVar, _var); if (!_var) return;

#define ESWeak_(var) ESWeak(var, weak_##var);
#define ESStrong_(var) ESStrong(weak_##var, _##var);

/** defines a weak `self` named `weakSelf` */
#define ESWeakSelf      ESWeak(self, weakSelf);
/** defines a strong `self` named `strongSelf` from `weakSelf` */
#define ESStrongSelf    ESStrong(weakSelf, strongSelf);

#define DLOG_CLASS_RELEASE_METHOD     NSLog(@"--%@ release---",[self class]);


#pragma mark - 定义警告宏
#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)

#pragma mark - 其他
#define REAL_LEN(W)	(kScreenWidth*(W)/1242)
#define REAL_LEN_750(W)	(kScreenWidth*(W)/750)
#define REAL_LEN_375(W)	(kScreenWidth*(W)/375)
#define REAL_FONTSIZE(S) [UIFont systemFontOfSize:REAL_LEN(S)]


//G－C－D
#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define MAIN(block) dispatch_async(dispatch_get_main_queue(), block)

//>>>>>>>>>>>>>>>>>>>>>>
//>>>  基础配置 ：系统  >>>
//>>>>>>>>>>>>>>>>>>>>>>
#define LAST_RUN_VERSION_KEY @"LAST_RUN_VERSION_KEY"

//>>>>>>>>>>>>>>>>>>>>
//>>>    用户信息    >>>
//>>>>>>>>>>>>>>>>>>>>
#define k_user_token [kUserDefaults objectForKey:@"user_token"]
#define k_user_uid [kUserDefaults objectForKey:@"user_id"]
#define k_user_phone [kUserDefaults objectForKey:@"user_phone"]
#define k_user_pwd [kUserDefaults objectForKey:@"user_pwd"]
#define k_user_nickname [kUserDefaults objectForKey:@"user_nickname"]
#define k_user_headsmall [kUserDefaults objectForKey:@"user_headsmall"]
#define k_user_money [kUserDefaults objectForKey:@"user_money"]
#define k_user_sign [kUserDefaults objectForKey:@"user_sign"]

#define k_user_occupation [kUserDefaults objectForKey:@"user_occupation"]//行业
#define k_user_duties [kUserDefaults objectForKey:@"user_duties"]//职业
#define k_user_business [kUserDefaults objectForKey:@"user_business"]
#define k_user_hobby [kUserDefaults objectForKey:@"user_hobby"]//爱好
#define k_user_truename [kUserDefaults objectForKey:@"user_truename"]//姓名
#define k_user_sex [kUserDefaults objectForKey:@"user_sex"]//性别 0男 1女
#define k_user_birthday [kUserDefaults objectForKey:@"user_birthday"]//生日
#define k_home_region_id [kUserDefaults objectForKey:@"home_region_id"]//家庭住址id
#define k_home_address [kUserDefaults objectForKey:@"home_address"]//家庭详细住址
#define k_region_id [kUserDefaults objectForKey:@"region_id"]//
#define k_region_name [kUserDefaults objectForKey:@"region_name"]//
#define k_user_qrcode [kUserDefaults objectForKey:@"user_qrcode"]//二维码
#define k_user_sn [kUserDefaults objectForKey:@"user_sn"]//今望码
#define k_media_id [kUserDefaults objectForKey:@"media_id"]//
#define k_shop_id [kUserDefaults objectForKey:@"shop_id"]//

#define k_user_city [kUserDefaults objectForKey:@"user_city"]
#define k_user_lat [kUserDefaults objectForKey:@"user_lat"]
#define k_user_lng [kUserDefaults objectForKey:@"user_lng"]

#define JWkScreenWidth [UIScreen mainScreen].bounds.size.width
#define JWkScreenHeight [UIScreen mainScreen].bounds.size.height

#define kScale                  JWkScreenWidth/750.0

#define CGRM(x,y,w,h) CGRectMake((x)*kScale, (y)*kScale, (w)*kScale, (h)*kScale)
#define CGSM(w,h) CGSizeMake((w)*kScale, (h)*kScale);

//颜色
#define kRGBColor(r, g, b)     [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define kRGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(r)/255.0 blue:(r)/255.0 alpha:a]
#define kRandomColor  KRGBColor(arc4random_uniform(256)/255.0,arc4random_uniform(256)/255.0,arc4random_uniform(256)/255.0)

#define kColorWithHex(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0 green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0 blue:((float)(rgbValue & 0xFF)) / 255.0 alpha:1.0]

//弱引用/强引用
#define kWeakSelf(type)   __weak typeof(type) weak##type = type;
#define kStrongSelf(type) __strong typeof(type) type = weak##type;

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//>>>  基础配置 ： 颜色 字体大小  >>>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#define k_themeColor kRGBColor(250, 250, 250) //kRGBColor(110, 110, 110)
#define k_bgViewColor_normal [UIColor whiteColor] //UIColorHex(0xf5f5f5)
#define k_fontColor_normal kRGBColor(42, 42, 42)

#define k_fontSize_1Class [UIFont systemFontOfSize:20]
#define k_fontSize_2Class [UIFont systemFontOfSize:17]
#define k_fontSize_3Class [UIFont systemFontOfSize:15]

// 检测block是否可用
#define BLOCK_EXEC(block, ...) if (block) { block(__VA_ARGS__); }

#pragma mark -----------

#define IOS9_OR_LATER  ( [[UIDevice currentDevice] systemVersion].floatValue >= 9.0 )
#define IOS8_OR_LATER  ( [[UIDevice currentDevice] systemVersion].floatValue >= 8.0 )
#define IOS7_OR_LATER  ( [[UIDevice currentDevice] systemVersion].floatValue >= 7.0 )
#define IOS6_OR_LATER  ( [[UIDevice currentDevice] systemVersion].floatValue >= 6.0 )
#define IOS5_OR_LATER  ( [[UIDevice currentDevice] systemVersion].floatValue >= 5.0 )
#define IOS4_OR_LATER  ( [[UIDevice currentDevice] systemVersion].floatValue >= 4.0 )
#define IOS3_OR_LATER  ( [[UIDevice currentDevice] systemVersion].floatValue >= 3.0 )

#define IOS8_OR_EARLIER !IOS9_OR_LATER
#define IOS7_OR_EARLIER !IOS8_OR_LATER
#define IOS6_OR_EARLIER !IOS7_OR_LATER
#define IOS5_OR_EARLIER !IOS6_OR_LATER
#define IOS4_OR_EARLIER !IOS5_OR_LATER
#define IOS3_OR_EARLIER !IOS4_OR_LATER

#define IS_SCREEN_3_INCH (CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size))
#define IS_SCREEN_4_INCH (CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size))
#define IS_SCREEN_55_INCH (CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size))
#define IS_SCREEN_47_INCH (CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size))


#pragma mark -----------

#define IMAGE_SCALE_FACTOR (IS_SCREEN_55_INCH?3:2)

//宏定义单利
#undef	AS_SINGLETON
#define AS_SINGLETON( __class ) \
- (__class *)sharedInstance; \
+ (__class *)sharedInstance;
#undef	DEF_SINGLETON
#define DEF_SINGLETON( __class ) \
- (__class *)sharedInstance \
{ \
return [__class sharedInstance]; \
} \
+ (__class *)sharedInstance \
{ \
static dispatch_once_t once; \
static __class * __singleton__; \
dispatch_once( &once, ^{ __singleton__ = [[[self class] alloc] init]; } ); \
return __singleton__; \
}

/* 微信 */
//#define kWechatAPPID       @"wxe335431b79068046"
#define kWechatAPPID       @"wx3566f4a32d1f126f"

#define kWechatAPPSecret   @"AGNq9Z6I9xQ7usWT2xPXc76pS9HUvcoq"
//微信支付商户号
#define kWechatMCHID       @"1300513101"
//安全校验码（MD5）密钥，商户平台登录账户和密码登录http://pay.weixin.qq.com
//平台设置的“API密钥”，为了安全，请设置为以数字和字母组成的32字符串。
#define kWechatPartnerKey  @"huichejianxiaochengxuhuichejianx"
//微信下单接口
#define kWechatPayUrl       @"https://api.mch.weixin.qq.com/pay/unifiedorder"
//微信回调地址
#define kWechatPayNotifyUrl  [NSString stringWithFormat:@"%@/api/Notify/wechat.php",kRequestHeaderUrl]
//统一下单请求参数键值
#define WXAPPID         @"appid"            // 应用id
#define WXMCHID         @"mch_id"           // 商户号
#define WXNONCESTR      @"nonce_str"        // 随机字符串
#define WXSIGN          @"sign"             // 签名
#define WXBODY          @"body"             // 商品描述
#define WXOUTTRADENO    @"out_trade_no"     // 商户订单号
#define WXTOTALFEE      @"total_fee"        // 总金额
#define WXEQUIPMENTIP   @"spbill_create_ip" // 终端IP
#define WXNOTIFYURL     @"notify_url"       // 通知地址
#define WXTRADETYPE     @"trade_type"       // 交易类型
#define WXPREPAYID      @"prepay_id"        // 预支付交易会话
#define WXATTACH        @"attach"           // 预支付交易会话

/* 支付宝 */
#define kAliPayAppKey @"2017102509513868"
#define kAliPaySecret @""
//支付宝私钥（用户自主生成，使用pkcs8格式的私钥）
#define kAlipayPrivateKey  @"MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCeVQK32VaGZOPnDPiF3NhGgk6baGBtNysn/0wwCdwzqmCkKLfjpmPu3LXt3Dxcak+9FldanlGhWwdcQnJT5ii4DoCOoA2h1hkn72s4OLL7RxFIM8hvxvuMwkK8W+vbyehHDErocoWsEe9IFEPwIl/4e3cSzf3AzYgvVUWv16Yg4Caw2aoIhOvL09DC+8oLKVj+6fPpr6ExOs6ZF/mUVXxTN1JDwlEkQUR4FmI6y2p9EewRZz1icbirJlX8KqQmE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6h2+ehqC63myUOBcHVYUSra2khw/D6CcMoXV5zw1JZHdjjTT4hVUBoTvfA2B0nfYVlAoGBALhn/W6ST4aeIDM87BA/1KBRJwpBtg1C4m4Wg7zwNQpxjkRHOvLmU2xCj2DlLekPcGwQkg+NFD4eReK5bsjBX8MmXOYwHjkzU46pFfkxerAJEqlZTfo3yFtMYS8tbUBtXO/yTAILptFICVqW0xSItPaitz9ZEBXqfuy6JmbmoOZ6"
//支付宝公钥
#define kAlipayPublicKey  @"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnlUCt9lWhmTj5wz4hdzYRoJOm2hgbTcrJ/9MMAncM6pgpCi346Zj7ty17dw8XGpPvRZXWp5RoVsHXEJyU+YouA6AjqANodYZJ+9rODiy+0cRSDPIb8b7jMJCvFvr28noRwxK6HKFrBHvSBRD8CJf+Ht3Es39wM2IL1VFr9emIOAmsNmqCITry9PQwvvKCylY/unz6a+hMTrOmRf5lFV8UzdSQ8JRJEFEeBZiOstqfRHsEWc9YnG4qyZV/CqkJhBBCgRMXvx/Zaj3qUyveskPCyGnKiAppK0rNwW4Z1Ask6XRZG6se9VD0ZMgm7KZ0f+UaMcWg3DBNXMyHdd5PssVHQIDAQAB"
//支付宝回调地址
#define kAlipayNotify_url  [NSString stringWithFormat:@"%@/pay/alipayNotify.php",kRequestHeaderUrl]


/* 环信 */
#define kEMKey @"1100180316146181#jinwang"//环信key
//环信推送证书
#ifdef DEBUG
#define kApnsCertName @"jinwang_aps_development"
#else
#define kApnsCertName @"jinwang_aps_distribute"
#endif
//默认所有用户的环信登录密码都是123456
#define kEMPassword @"123456"


#pragma mark -------------判断是否为空
//字符串是否为空
#define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )
//数组是否为空
#define kArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)
//字典是否为空
#define kDictIsEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)
//是否是空对象
#define kObjectIsEmpty(_object) (_object == nil \
|| [_object isKindOfClass:[NSNull class]] \
|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \
|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0))

#endif /* Config_h */
